<!-- 动态树形菜单页面 -->
<template>
  <div class="common_screen">

    <!-- 布局容器 -->
    <el-container :style="containerStyle">
      <!-- 头部 -->
      <el-header>

        <el-row>
          <el-col :span="12">
            <div>
              <p>后台管理系统</p>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="logout">
              <el-dropdown @command="handleCommand">
                <span class="el-dropdown-link">
                  {{userName}}<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="userInfo">个人信息</el-dropdown-item>
                  <el-dropdown-item command="updatePwd">修改密码</el-dropdown-item>
                  <el-dropdown-item command="logout">注销登录</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </el-col>
        </el-row>
      </el-header>

      <!-- 中间主体 -->
      <el-container>
        <!-- 左边导航栏 -->
        <el-aside width="200px">

          <el-menu
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            :default-active="'index'"> <!-- router属性：表示使用router自由切换 -->
            <!-- 动态配置菜单-->
            <template v-for="item in menuList">
              <!-- 是否父级权限判断 -->
              <el-submenu :index=item.index v-if="!item.isContent">
                <template slot="title">
                  <i :class=item.icon></i>
                  {{item.name}}
                </template>
                <tree_menu v-bind:menuData=item.children></tree_menu>
              </el-submenu>

              <el-menu-item :index=item.index v-else>
                <i :class=item.icon></i>
                <span slot="title">{{item.name}}</span>
              </el-menu-item>

            </template>

          </el-menu>
        </el-aside>
        <!-- 右边主界面 -->
        <el-main>
          <router-view/>
        </el-main>
      </el-container>


    </el-container>

  </div>
</template>


<script>

  //使用import导入tree_menu子组件
  import tree_menu from '@/components/common/tree_menu.vue'

  export default {
    //数据类型
    data () {
      return {
        //布局容器css样式配置
        containerStyle: {
          height: '100%',
          width: '100%'
        },
        userName:"张三",
        //菜单动态数据
        menuList: [
          {
            name: '系统首页',
            index: '/index',
            icon: 'el-icon-location',
            isContent: true
          },
          {
            name: '系统管理',
            index: 'system',
            icon: 'el-icon-setting',
            isContent: false,
            children: [
              {
                name: '用户管理',
                index: '/system/userList'
              }, {
                name: '角色管理',
                index: '/system/roleList'
              }, {
                name: '权限管理',
                index: '/system/rightList'
              }
            ]
          },
          {
            name: '日志管理',
            index: 'log',
            icon: 'el-icon-view',
            isContent: false,
            children: [
              {
                name: '登陆日志',
                index: '/log/login'
              }, {
                name: '系统日志',
                index: '/log/system'
              }, {
                name: '日志监控',
                index: '/log/newest'
              }
            ]
          }
        ]
      }
    },
    //在components中引入子组件
    components: {
      tree_menu: tree_menu
    },
    //初始化加载
    mounted: function () {

    },
    //具体js方法
    methods: {
      handleOpen (key, keyPath) {
        console.log(key, keyPath)
      },
      handleClose (key, keyPath) {
        console.log(key, keyPath)
      },
      //下来信息点击事件
      handleCommand (command) {
        switch (command) {
          case 'userInfo':
            this.openUserInfo()
            break
          case 'updatePwd':
            this.openUpdatePwd()
            break
          case 'logout':
            this.logout()
            break
        }
      },
      //注销登录
      logout () {
        this.$router.push({name: 'login'})//注销封路
      },
      //打开个人信息窗口
      openUserInfo () {
        this.$message('打开个人信息窗口');
      },
      //打开修改密码窗口
      openUpdatePwd () {
        this.$message('打开修改密码窗口');
      }
    }
  }
</script>


<style scoped>


  .el-header {
    background-color: #545c64;
    color: #333;
    line-height: 60px;
  }

  .el-header p {
    /*字体形状*/
    font-family: "微软雅黑";
    font-size: 22px;
    /*位置*/
    text-align: left;
    /*外边距*/
    margin: 0 20px 0 0;
    /*字体颜色*/
    color: #FFF;
  }

  .el-aside {
    background-color: #545c64;
  }

  .logout {
    /*位置*/
    text-align: right;
    /*外边距*/
    margin: 0 0 0 100px;
  }

  .logout span {
    color: #FFF;
    font-size: 15px;
  }

  .logout a {
    color: #FFF;
    font-size: 15px;
    /*取消a标签的下划线*/
    text-decoration: none;
  }

  .logout a span {
    color: #FFF;
    font-size: 15px;
    margin-left: 5px;
    /*取消a标签的下划线*/
    text-decoration: none;
  }

</style>
